package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjbusiness;
import com.chezhujie.www.persistence.CzjbusinessMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 商家信息表
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjbusinessService extends BaseService<Czjbusiness> {
    @Autowired
    private CzjbusinessMapper czjbusinessMapper;

    @Autowired
    public void setBaseMapper(CzjbusinessMapper czjbusinessMapper) {
        this.baseMapper = czjbusinessMapper;
    }

    @Override
    public void insert(Czjbusiness czjbusiness) {
        czjbusiness.setCreateTime(new Date());
        czjbusiness.setApproveStatus(0);
        czjbusiness.setDelFlag(0);
        super.insert(czjbusiness);
    }

    public void checkEntity(Czjbusiness czjbusiness) throws ClassCheckException {
        if(czjbusiness.getBusinessName()!=null&&czjbusiness.getBusinessName().length()>255){
            throw new ClassCheckException("商家信息表商家名称不能超过255个字符");
        }
        if(czjbusiness.getStartTime()!=null&&czjbusiness.getStartTime().length()>50){
            throw new ClassCheckException("商家信息表营业开始时间不能超过50个字符");
        }
        if(czjbusiness.getEndTime()!=null&&czjbusiness.getEndTime().length()>50){
            throw new ClassCheckException("商家信息表营业结束时间不能超过50个字符");
        }
        if(czjbusiness.getRemarker()!=null&&czjbusiness.getRemarker().length()>100){
            throw new ClassCheckException("商家信息表备注不能超过100个字符");
        }
    }
    public void checkListEntity(List<Czjbusiness> listCzjbusiness) throws ClassCheckException {

        for (Czjbusiness czjbusiness : listCzjbusiness) {
            checkEntity(czjbusiness);
        }

    }
    /**
     * 修改审批状态
     * @param id
     * @param approveStatus
     */
    public void changeApprove(String id, Integer approveStatus) {
        Czjbusiness entity = queryById(id);
        entity.setApproveStatus(approveStatus);
        entity.setApproveTime(new Date());
        update(entity);
    }

	public Czjbusiness getBusinessByTuserid(String username) {
		return czjbusinessMapper.getBusinessByTuserid(username);
	}

    public Czjbusiness queryByUserId(String userId) {
        return czjbusinessMapper.queryByUserId(userId);
    }

    public void updateUnameByUserId(Map<String, Object> map)  {
        czjbusinessMapper.updateUnameByUserId(map);
    }
}
